package com.cnebula.dataprocess.hive.job.consumer;

import org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.starter.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cnebula.dataprocess.common.hive.HiveDataPass;
import com.cnebula.dataprocess.hive.job.serivce.HiveService;
import com.google.gson.Gson;

@Service
@RocketMQMessageListener(topic = "hive-datapass-topic", consumerGroup = "hive-datapass-consumer")
public class HiveDataPassConsumer  implements RocketMQListener<HiveDataPass> {
	
	private static final Logger log = LoggerFactory.getLogger(HiveDataPassConsumer.class);

	private Gson gson = new Gson();
	
	@Autowired
	HiveService hiveService;

	@Override
	public void onMessage(HiveDataPass arg0) {
		
		log.info("=============================receive hive datapass job ============================");
		log.info(gson.toJson(arg0));
		log.info("===================================================================================");
		
		String tableName = arg0.getTable();
		String passColumn = arg0.getPassColumn();
		String jobId = arg0.getJobId();
		String taskId = arg0.getTaskId();
		
		hiveService.dataPass(taskId, jobId, tableName, passColumn);
	}

}
